<div class="layui-form" lay-filter="layuiadmin-form-resource" style="padding: 20px 0 0 0;">
    <div class="layui-form-item">
        <label class="layui-form-label">资源名称</label>
        <div class="layui-input-inline">
            <script type="text/html" template>
                <input type="text" name="name" value="{{ d.params.name || '' }}" lay-verify="required"
                       placeholder="请输入资源名称"
                       autocomplete="off" class="layui-input">
            </script>

        </div>
    </div>
    <div class="layui-form-item">
        <label class="layui-form-label">资源编码</label>
        <div class="layui-input-inline">
            <script type="text/html" template>
                <input type="text" name="code" value="{{ d.params.code || '' }}" lay-verify="required"
                       placeholder="请输入资源编码" autocomplete="off" class="layui-input">
            </script>
        </div>
    </div>
    <div class="layui-form-item">
        <label class="layui-form-label">资源类型</label>
        <div class="layui-input-inline">
            <script type="text/html" template>
                <input type="radio" name="type" value="1" title="菜单" {{ d.params.type===1 ? 'checked' : '' }}>
                <input type="radio" name="type" value="2" title="按钮" {{ d.params.type===2 ? 'checked' : '' }}>
            </script>
        </div>
    </div>
    <div class="layui-form-item">
        <label class="layui-form-label">资源地址</label>
        <div class="layui-input-inline">
            <script type="text/html" template>
                <input type="text" name="jump" value="{{ d.params.jump || '' }}" lay-verify="required"
                       placeholder="请输入资源url" autocomplete="off" class="layui-input">
            </script>
        </div>
    </div>
    <div class="layui-form-item" id="parent_resource_id">
        <label class="layui-form-label">上级资源</label>
        <div class="layui-input-inline">
            <script type="text/html" template>
                <input type="text" id="parentName" disabled value="{{ d.params.parentName || '' }}"
                       placeholder="请选择上级资源" autocomplete="off" class="layui-input">
                <input type="hidden" id="parentId" disabled name="parentId" value="{{ d.params.parentId || '' }}"
                       placeholder="隐藏域" autocomplete="off" class="layui-input">
            </script>
        </div>
    </div>
    <div class="layui-form-item">
        <label class="layui-form-label">资源图标</label>
        <div class="layui-input-inline">
            <script type="text/html" template>
                <input type="text" name="icon" value="{{ d.params.icon || '' }}" placeholder="请输入资源图标"
                       autocomplete="off" class="layui-input">
            </script>
        </div>
    </div>
    <div class="layui-form-item">
        <label class="layui-form-label">显示排序</label>
        <div class="layui-input-inline">
            <script type="text/html" template>
                <input type="text" name="sort" value="{{ d.params.sort || '' }}" placeholder="请输入排序数字"
                       autocomplete="off" class="layui-input">
            </script>
        </div>
    </div>
    <div class="layui-form-item" lay-filter="available">
        <label class="layui-form-label">资源状态</label>
        <div class="layui-input-block">
            <script type="text/html" template>
                <input type="radio" name="available" value="0" title="可用" {{ d.params.available=== 0
                       ? 'checked' : '' }}>
                <input type="radio" name="available" value="1" title="禁用" {{ d.params.available=== 1
                       ? 'checked' : '' }}>
                <!--<input type="radio" name="available" value="1" title="禁用33"-->
                       <!--{{# if(1>0){ }}-->
                        <!--checked-->
                        <!--{{#  } else { }}-->
                        <!--''-->
                        <!--{{#  } }}-->
                <!--&gt;-->
            </script>
        </div>
    </div>
    <div class="layui-form-item">
        <label class="layui-form-label"></label>
        <div class="layui-input-inline">
            <input type="button" lay-submit lay-filter="LAY-resource-front-submit" value="确认" class="layui-btn">
        </div>
    </div>
</div>

<script>
    // 父菜单Id和Name
    let parentId, parentName;
    layui.use(['admin', 'form', 'upload', 'laytpl'], function () {
        let $ = layui.$
            , upload = layui.upload
            , admin = layui.admin
            , view = layui.view
            , table = layui.table
            , form = layui.form
            , laytpl = layui.laytpl;


        $(document).on('click', '#parent_resource_id', function () {
            let data = {};
            admin.popup({
                title: '资源树'
                , area: ['300px', '450px']
                , id: 'LAY-popup-resource-parent'
                , shadeClose: true
                , success: function (layero, index) {

                    view(this.id).render('user/resource/tree_panel', data).done(function () {
                        // form.render(null, 'layuiadmin-form-useradmin');

                    });
                }
            });
        });
    });

    /**
     * 获取点击的树节点
     * @param data 获取点击的数据
     * @constructor
     */
    function getTreeChooseData(data) {
        parentId = data.id;
        parentName = data.title;
        document.getElementById('parentId').value = parentId;
        document.getElementById('parentName').value = parentName;
    }
</script>